package com.gaff.emp.core.config;

import com.gaff.emp.core.hbase.HBaseAdminTemplate;
import com.gaff.emp.core.hbase.HBaseTemplate;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "HBase", name = "enable", havingValue = "true")
public class HBaseConfig implements DisposableBean {

    @Value("${HBase.quorum:localhost:2181}")
    private String quorum;

    @Bean
    public HBaseAdminTemplate hBaseAdminTemplate() {
        return new HBaseAdminTemplate(quorum);
    }

    @Bean
    public HBaseTemplate hBaseTemplate() {
        return new HBaseTemplate(quorum);
    }

    @Override
    public void destroy() throws Exception {
        hBaseAdminTemplate().close();
        hBaseTemplate().close();
    }
}
